package com.yami.shop.admin.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yami.shop.bean.dto.MapObject;
import com.yami.shop.bean.model.LoginHist;
import com.yami.shop.service.LoginHistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;

@Api(tags = "首页接口")
@RestController
@RequestMapping("/main")
public class MainInfoController {
    @Autowired
    private LoginHistService loginHistService;

    @ApiOperation("获取数据")
    @GetMapping
    public ResponseEntity get() {
        MapObject mapObject = new MapObject();
        Date today = new Date();
        int count = loginHistService.count(Wrappers.lambdaQuery(new LoginHist())
                .between(LoginHist::getLoginTime, DateUtil.beginOfDay(today), DateUtil.endOfDay(today)));
        mapObject.add("todayH5Login", new MapObject()
                .add("data", count)
                .add("msg", "今日H5登录总次数"));

        mapObject.add("todayH5LoginByAccount", new MapObject()
                .add("data", loginHistService.countByAccountToday())
                .add("msg", "今日H5登录账户次数"));


        return ResponseEntity.ok(mapObject);
    }
}
